/**
 * Copyright (c) 2022 www.talkweb.com.cn Inc. AlL rights reserved.
 */
package com.sky.wsp.mybatis.plus.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.wsp.mybatis.plus.dao.UserMapper;
import com.sky.wsp.mybatis.plus.dao.entity.UserEntity;
import com.sky.wsp.mybatis.plus.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 * 用户表 Service服务实现类
 *
 * @author wangshaopeng@talkweb.com.cn
 * @Date 2023-01-11
 */
@Service
@Transactional
public class UserXmlServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements IUserService {

    @Resource
    private UserMapper userMapper;

    @Override
    @Transactional(readOnly = true)
    public Page<UserEntity> findPage(UserEntity query, Page<UserEntity> page) {
        return userMapper.findPage(query, page);
    }

    @Override
    @Transactional(readOnly = true)
    public List<UserEntity> findList(UserEntity query) {
        return userMapper.findList(query);
    }

    @Override
    @Transactional(readOnly = true)
    public UserEntity getById(Serializable id) {
        return userMapper.myFindById(id);
    }

    @Override
    public boolean save(UserEntity entity) {
        entity.setCreateTime(new Date());
        entity.setUpdateTime(entity.getCreateTime());
        return userMapper.mySave(entity);
    }


    @Override
    public boolean updateById(UserEntity entity) {
        entity.setUpdateTime(new Date());
        return userMapper.myUpdate(entity);
    }

    @Override
    public boolean delete(Long id) {
        // 物理删除
        return userMapper.myDeleteById(id);
    }
}
